package com.wxapp.custom.api.feign;

import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.util.check.CheckUtil;
import com.wxapp.custom.api.feign.fallback.UploadFallBack;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author lgl
 * @Description 上传
 * @Datetime 2023/2/13 13:49
 * @Modified By
 */
@FeignClient(value = "wxapp-system", fallback = UploadFallBack.class)
public interface UploadFeign {
    @PostMapping(value = {"/upload/image"})
    ResultVm<String> uploadImage(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws Exception;

    @PostMapping(value = "/upload/image/{path}")
    ResultVm<String> uploadImage(HttpServletRequest request, @RequestParam("file") MultipartFile file, @PathVariable(value = "path") String path) throws Exception;

    default ResultVm<String> uploadImages(HttpServletRequest request, @RequestParam("file") MultipartFile file, @PathVariable(value = "path") String path) throws Exception {
        if (CheckUtil.isNotNullString(path)){
            return uploadImage(request,file,path);
        }
        return uploadImage(request,file);
    }
    @GetMapping("file/file/{name}")
    ResultVm<String> getFile(@RequestBody HttpServletResponse response, @PathVariable(value = "name") String name);
}
